﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Classes.*;
    import Classes.util.*;
    import Classes.sim.*;
    import Classes.effects.*;
    import Classes.actions.*;

    public class GMDebugPathing extends GMDefault {

        public static const DELIVERY_VEHICLE:String = "van_delivery";
        public static const TOUR_BUS:String = "tourismbus";

        protected var m_downObject:MapResource = null;
        protected var m_upObject:MapResource = null;
        protected var m_count:int = 0;

        public function GMDebugPathing(){
            m_cursorImage = EmbeddedArt.trainUIPick;
            m_showMousePointer = true;
        }
        override protected function isObjectHighlightable(_arg1:GameObject):Boolean{
            return (isObjectSelectable(_arg1));
        }
        override public function onMouseMove(_arg1:MouseEvent):Boolean{
            super.onMouseMove(_arg1);
            return (true);
        }
        override public function onMouseOut(_arg1:MouseEvent):Boolean{
            super.onMouseOut(_arg1);
            return (true);
        }
        override public function onMouseDown(_arg1:MouseEvent):Boolean{
            super.onMouseDown(_arg1);
            if (this.m_downObject == null){
                this.m_downObject = (m_selectedObject as MapResource);
            };
            return (true);
        }
        protected function doTourBus(_arg1:Business):void{
            var business:* = _arg1;
            Sounds.play("tourbus_start");
            Sounds.play("tourbus_engine_loop", 0, Sounds.LOOPING);
            var nearRoad:* = Global.world.citySim.roadManager.findClosestRoad(business.getPosition());
            var startRoad:* = Global.world.citySim.roadManager.findRandomRoadOnScreen(nearRoad);
            var m_tourBus:* = new TourBus(TOUR_BUS, false);
            m_tourBus.setPosition(startRoad.getHotspot().x, startRoad.getHotspot().y);
            Global.world.citySim.npcManager.addVehicle(m_tourBus);
            var actions:* = m_tourBus.getStateMachine();
            actions.removeAllStates();
            actions.addActions(new ActionAnimationEffect(m_tourBus, EffectType.VEHICLE_POOF), new ActionNavigate(m_tourBus, business, startRoad).setPathType(RoadManager.PATH_ROAD_ONLY), new ActionFn(m_tourBus, function ():void{
                Sounds.stop("tourbus_engine_loop");
                Sounds.play("tourbus_honk");
            }), new ActionProgressBar(m_tourBus, business, ZLoc.t("Main", "UnloadingTourists")), new ActionFn(m_tourBus, function ():void{
                Sounds.play("tourbus_start");
                Sounds.play("tourbus_engine_loop", 0, Sounds.LOOPING);
            }), new ActionNavigate(m_tourBus, startRoad, business), new ActionFn(m_tourBus, function ():void{
                Sounds.stop("tourbus_engine_loop");
                Sounds.play("tourbus_stop");
            }), new ActionDie(m_tourBus));
        }
        public function getCommodity(_arg1:Storage, _arg2:MapResource):void{
            var storage:* = _arg1;
            var target:* = _arg2;
            Sounds.play("truck_start");
            Sounds.play("truck_engine_loop", 0, 15);
            var startRoad:* = Global.world.citySim.roadManager.findClosestRoad(storage.getHotspot());
            var m_deliveryVan:* = Global.world.citySim.npcManager.createVehicleByName(startRoad, DELIVERY_VEHICLE, false);
            var actions:* = m_deliveryVan.getStateMachine();
            actions.removeAllStates();
            actions.addActions(new ActionNavigate(m_deliveryVan, target, storage).setPathType(RoadManager.PATH_ROAD_ONLY), new ActionFn(m_deliveryVan, function ():void{
                Sounds.stop("truck_engine_loop");
                Sounds.play("truck_honk");
                Sounds.play("truck_off");
            }), new ActionDie(m_deliveryVan));
        }
        override public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local2:NPC;
            super.onMouseUp(_arg1);
            this.m_upObject = (m_highlightedObject as MapResource);
            if ((((((this.m_upObject == this.m_downObject)) && (!((this.m_upObject == null))))) && ((this.m_count == 0)))){
                this.highlightObject(this.m_upObject);
                this.m_count++;
                return (true);
            };
            if (((((!((this.m_upObject == null))) && ((this.m_downObject == this.m_upObject)))) && ((this.m_upObject is Business)))){
                this.doTourBus((this.m_upObject as Business));
            } else {
                if (((((!((this.m_upObject == null))) && (!((this.m_downObject == null))))) && (!((this.m_upObject == this.m_downObject))))){
                    if ((this.m_downObject is Storage)){
                        this.getCommodity((this.m_downObject as Storage), this.m_upObject);
                    } else {
                        _local2 = Global.world.citySim.npcManager.createWalker(this.m_downObject, true);
                        _local2.getStateMachine().addActions(new ActionNavigate(_local2, this.m_upObject, this.m_downObject), new ActionDie(_local2));
                    };
                } else {
                    if (this.m_downObject == null){
                        Global.world.citySim.npcManager.makeRandomVehicle();
                    };
                };
            };
            Global.world.removeGameMode(this);
            return (true);
        }

    }
}//package GameMode 
